package com.pi.nbcenter.device.service.e;

import com.pi.nbcenter.device.bean.dto.nb.BaseInfo;
import com.pi.nbcenter.device.bean.dto.nb.SupportInfo;
import com.pi.nbcenter.device.entity.auto.BasePartnerInfo;
import com.pi.nbcenter.device.mapper.auto.BaseNbPartnerInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lusj
 * @version V1.0
 * @Type SupplierService
 * @Desc 供应商查询信息
 * @date 2018/6/24
 */
@Service
public class SupplierService {

    @Autowired
    private BaseEService baseEService;

    @Autowired
    private BaseNbPartnerInfoMapper baseNbPartnerInfoMapper;
    /**
     * 供应商接口
     *
     * @param supportInfo 供应商参数
     * @return
     */
    public BaseInfo addSupportCompany(SupportInfo supportInfo) {
        BaseInfo baseInfo = new BaseInfo();
        Map<String, Object> params = new HashMap<>();
        params.put("name", supportInfo.getName());
        params.put("address", supportInfo.getAddress());
        params.put("corporate", supportInfo.getCorporate());
        params.put("corporatePhone", supportInfo.getCorporatePhone());
        params.put("principal", supportInfo.getPrincipal());
        params.put("principalPhone", supportInfo.getPrincipalPhone());
        String url = "&code=addSupportCompany";
        String  partnerCode = baseEService.commonPostMethod(url, params);
        BasePartnerInfo basePartnerInfo =  support2partnerInfo(supportInfo,partnerCode);
         baseNbPartnerInfoMapper.insert(basePartnerInfo);
        baseInfo.setResult(partnerCode);
        return baseInfo;
    }

    public static BasePartnerInfo support2partnerInfo(SupportInfo supportInfo,String partnerCode) {
        if (supportInfo == null) {
            return null;
        }
        BasePartnerInfo basePartnerInfo = new BasePartnerInfo();
      //TODO 这里要修改一下  basePartnerInfo.setPartnerCode(partnerCode);
        basePartnerInfo.setPartnerCode(11111L);
        basePartnerInfo.setPartnerName(supportInfo.getName());
        basePartnerInfo.setAddress(supportInfo.getAddress());
        basePartnerInfo.setCorporate(supportInfo.getCorporate());
        basePartnerInfo.setCorporatePhone(supportInfo.getCorporatePhone());
        return basePartnerInfo;
    }


}
